<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
   
	<body>
		<input type="button" value="打开窗口" onclick="openwin()"/>
		<br />
		<br />
		<input type="button"value="关闭窗口" onclick="closewin()"/>
		<br />
		<br />
		<input type="button"  value="检测窗口是否关闭"onclick="checkwin()" />
		<p id="msg"></p>
		<script type="text/javascript">
			var win=null;
			function openwin(){
				win=window.open('','我的窗口','width=400,height=200,left=300,top=100');
				win.document.write(win.name+'<br />');
				win.document.write(win.parent);
			}
			function closewin(){
				if(win!=null){
					win.close();
				}else{
					alert("没有新窗口打开");
				}
			}
			function checkwin(){
				var s;
			if(win){
			s=(win.closed?'窗口已关着':'窗口打开着未关闭');
			}else{
				s="窗口没有被打开"
			}
			var msg=document.getElementById('msg')
			msg.innerHTML=s;
			}
			
		</script>
	</body>
</html>
